#pragma once

#include "Level.h"

/**
 * Level created through Cellular Automata algorithm using 4-5 rule.
 * Every tile starts with an x% chance to have a wall, and then n number
 * of iterations are executed over the entire map. For each iteration,
 * if a tile has 5 or more neighbors with walls, including itself, then
 * that tile has a wall. If a tile has 4 or less neighbors with walls,
 * then it doesn't get a wall. This produces a "cave-like" level
 * layout.
 */
class CALevel : public Level {
protected:
	/** Random layout generation algorithm */
	void generateLayout();
	/**
	 * Runs a bucket fill algorithm on a tile map for Cellular Automata,
	 * which is used to check for unconnected level chunks.
	 * @param walls 3D array of wall states, as described in generateLayout()
	 * @param x The column to start the algorithm at
	 * @param y The row to start the algorithm at
	 */
	void bucketFill(bool*** walls, int x, int y);
public:
	/**
	 * Constructor if this Level is the first Level in a Dungeon
	 *
	 * @param cols Number of columns
	 * @param rows Number of rows
	 * @param levelNum Position in the list of Dungeon levels
	 * @param dlevel Danger level
	 * @param dungeon The Dungeon this level is contained in
	 */
	CALevel(int x, int y, int levelNum, int dlevel, Dungeon* dungeon);

	/**
	 * Constructor if this Level is not the first level in a Dungeon
	 *
	 * @param cols Number of columns
	 * @param rows Number of rows
	 * @param level The Level above this one
	 */
	CALevel(int x, int y, Level* level);
	/** Destructor */
	~CALevel();
};

